package testGridTree.action;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import testGridTree.GridTreeDao;
import testGridTree.GridTreeUtil;

/**
 * 懒加载表格树演示:查询指定的父节点下面的子节点.
 * 在点击节点前面的+号的时候,将提交到这个action处理.
 * connect me:419723443@qq.com
 */
public class TableTreeLazyAction  extends Action {
	 // 每页行数
    private static int DEFAULT_PAGE_SIZE = 10;
	/**
	 * 获取类型的下拉菜单数据
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
	  	String parentId = request.getParameter("pId");
    	GridTreeDao dao = new GridTreeDao();
		List list = new ArrayList();		
		try {
			list = dao.getListByParent(parentId);
			// 调用工具类的方法得到json字符串。
			String jsonStr = GridTreeUtil.getJsonStr(list);
			response.setContentType("text/html; charset=UTF-8");
			System.out.println("懒加载子串:"+jsonStr);
			PrintWriter out = response.getWriter();
			out.println(jsonStr);
		} catch (Exception e) {
			e.printStackTrace();
		}		
		return null;
	}
}
